package com.wuye.web;


import org.json.JSONObject;

@SuppressWarnings("serial")
public class Result<E> implements java.io.Serializable {
    public Result(ST st) {
        this.st = st;
        this.result = null;
    }

    public Result(ST st, E result) {
        this.st = st;
        this.result = result;
    }

    public ST st;
    public E result;

    public JSONObject toJSONObject() {
        return toJSONObject(result);
    }

    public String toJSONString() {
        return toJSONObject(result).toString();
    }

    public JSONObject toJSONObject(Object inResult) {
        JSONObject json = new JSONObject();
        if (inResult != null)
            json.accumulate("result", inResult);
        else {
            json.accumulate("result", result);
        }
        json.accumulate("code", st.state);
        if (st.description != null)
            json.accumulate("description", st.description);
        return json;
    }

}
